@import '../../../style/common/index.less';
@import './reset.less';

.@{radio-prefix-cls}-wrapper {
  .radio-reset-component();
  position: relative;
  display: inline-flex;
  align-items: center;
  box-sizing: border-box;
  cursor: pointer;

  &-disabled {
    cursor: not-allowed;
  }

  &::after {
    display: inline-block;
    width: 0;
    overflow: hidden;
    content: '\a0';
  }

  span.@{radio-prefix-cls} + * {
    margin-right: @space-8;
    padding-right: 8px;
    padding-left: 8px;
  }
}

.@{radio-predix-button-cls}-wrapper {
  .radio-reset-component();
  position: relative;
  display: inline-block;
  padding: @space-4 @space-12;
  background-color: @white-main;
  border: 1px solid @gray-4;
  cursor: pointer;
  transition: color 0.3s, background-color 0.3s, border-color 0.3s, box-shadow 0.3s;

  &:first-child {
    border-radius: 2px 0 0 2px;
  }

  &:last-child {
    border-radius: 0 2px 2px 0;
  }

  &:hover {
    color: @info-hover;
  }

  &:focus-within {
    z-index: 1;
    box-shadow: @radio-focus-shadow;
  }

  &:not(:first-child):not(&-disabled):not(&-checked) {
    border-left: none;

    &::before {
      position: absolute;
      top: -1px;
      left: -1px;
      box-sizing: content-box;
      width: 1px;
      height: calc(100% + 2px);
      background-color: @gray-4;
      transition: background-color 0.3s;
      content: ' ';
    }
  }

  .@{radio-group-prefix-cls}-large & {
    font-size: @font-size-base;
    line-height: @line-height-lg;
  }

  .@{radio-group-prefix-cls}-small & {
    font-size: @font-size-sm + 0.125;
    line-height: @line-height-sm;
  }

  &-checked:not(&-disabled) {
    z-index: 1;
    color: @info-active;
    border-color: @info-active;

    &:hover {
      color: @info-hover;
    }

    &:not(:first-child) {
      border-left: none;

      &::before {
        position: absolute;
        top: -1px;
        left: -1px;
        box-sizing: content-box;
        width: 1px;
        height: calc(100% + 2px);
        background-color: @info-active;
        transition: background-color 0.3s;
        content: ' ';
      }
    }
  }

  &-disabled {
    color: @gray-4;
    background-color: @white-3;
    border-color: @gray-4;
    cursor: not-allowed;

    &:hover {
      color: @gray-4;
      background-color: @white-3;
      border-color: @gray-4;
    }

    &:not(:first-child) {
      border-left: none;
    }
  }

  &-disabled&-checked {
    color: @info-disable;
    border-color: @info-disable;
    box-shadow: none;
  }
}

.@{radio-predix-slider-cls}-wrapper {
  .radio-reset-component();
  position: relative;
  z-index: 1;
  padding: @radio-slider-base-padding calc(@radio-slider-base-padding + @space-8);
  color: fade(@gray-main, 70%);
  cursor: pointer;
  transition: color 0.3s cubic-bezier(1, 0.21, 0, 0.38);

  &-checked {
    color: @gray-main;
  }

  &-solid {
    color: fade(@white-main, 90%);
  }

  &-disabled {
    color: @gray-4;
    cursor: not-allowed;
  }

  .@{radio-group-prefix-cls}-large & {
    font-size: @font-size-base;
    line-height: @line-height-lg;
  }

  .@{radio-group-prefix-cls}-small & {
    font-size: @font-size-sm;
    line-height: @line-height-lg + 0.125;
  }
}

.@{radio-group-prefix-cls}-slider {
  position: relative;
  padding: calc(@radio-slider-base-padding + 2px) @radio-slider-base-padding;
  background-color: @radio-slider-bac;
  border-radius: 2px;

  &.@{radio-group-prefix-cls}-small {
    padding: @radio-slider-base-padding;
  }

  &.@{radio-group-prefix-cls}-large {
    padding: calc(@radio-slider-base-padding + @space-4) @radio-slider-base-padding;
  }
}

.@{radio-group-prefix-cls}-line {
  position: absolute;
  top: 4px;
  height: calc(100% - 8px);
  background-color: @white-3;
  border-radius: 2px;
  box-shadow: 0 2px 8px -2px #0000000d, 0 1px 4px -1px #00000012, 0 0 1px #00000014;
  transition: left @radio-group-line-bezier, width @radio-duration;

  &-solid {
    background-color: @blue-main;
  }
}

.@{radio-prefix-cls}-button,
.@{radio-prefix-cls}-slider {
  position: absolute;
  top: 0;
  left: 0;
  z-index: -1;
  width: 100%;
  height: 100%;

  input[type='radio'] {
    width: 0;
    height: 0;
    opacity: 0;
    pointer-events: none;
  }
}

// 一般状态
.@{radio-prefix-cls} {
  .radio-reset-component();
  position: relative;
  display: inline-block;
  outline: none;
  cursor: pointer;

  &:hover .@{radio-inner-prefix-cls},
  &-input:focus + .@{radio-inner-prefix-cls} {
    border-color: @info-default;
  }

  &-input:focus + .@{radio-inner-prefix-cls} {
    box-shadow: @radio-focus-shadow;
  }

  &-inner {
    &::after {
      position: absolute;
      top: 50%;
      left: 50%;
      display: block;
      width: @space-8;
      height: @space-8;
      margin-top: -(@space-8 / 2);
      margin-left: -(@space-8 / 2);
      background-color: var(--radio-inner-circle-color);
      border-top: 0;
      border-left: 0;
      border-radius: 50%;
      transform: scale(0);
      opacity: 0;
      transition: all @radio-duration ease-in-out;
      content: ' ';
    }

    position: relative;
    top: 0;
    left: 0;
    display: block;
    width: @space-16;
    height: @space-16;
    background-color: var(--radio-inner-back-color);
    border: 1px solid @gray-3;
    border-radius: 50%;
    transition: all @radio-duration;
  }

  input {
    position: absolute;
    top: 0;
    right: 0;
    bottom: 0;
    left: 0;
    z-index: 1;
    cursor: pointer;
    opacity: 0;
  }

  &&-disabled {
    .@{radio-inner-prefix-cls} {
      border-color: @gray-4;
    }
  }
}

// 选中状态
.@{radio-prefix-cls}-checked {
  &::after {
    position: absolute;
    top: 0;
    left: 0;
    box-sizing: border-box;
    width: 100%;
    height: 100%;
    border: 1px solid @info-default;
    border-radius: 50%;
    animation: dtRadioBorder 0.36s ease-in-out;
    animation-fill-mode: both;
    content: '';
  }

  .@{radio-inner-prefix-cls} {
    border-color: var(--radio-inner-circle-color);

    &::after {
      transform: scale(((unit(@space-8) + 2) / unit(@space-8)));
      opacity: 1;
      animation: dtRadioEffect 0.36s ease-in-out;
    }
  }
}

// 禁用状态
.@{radio-prefix-cls}-disabled {
  cursor: not-allowed;

  .@{radio-inner-prefix-cls} {
    background-color: var(--radio-inner-back-disabled-color);
    cursor: not-allowed;

    &::after {
      background-color: @gray-4;
    }
  }

  .@{radio-prefix-cls}-input {
    cursor: not-allowed;
  }

  & + span {
    color: var(--radio-font-disabled-color);
    cursor: not-allowed;
    transition: all @radio-duration ease-in-out;
  }
}

// 动画组
@keyframes dtRadioBorder {
  0% {
    transform: scale(0);
    opacity: 0.5;
  }

  100% {
    transform: scale(1.8);
    opacity: 0;
  }
}

@keyframes dtRadioEffect {
  0% {
    transform: scale(0);
    opacity: 0;
  }

  80% {
    transform: scale(((unit(@space-12)) / unit(@space-8)));
    opacity: 0.8;
  }

  100% {
    transform: scale(((unit(@space-8) + 2) / unit(@space-8)));
    opacity: 1;
  }
}
